# ================== for loops  ===============
for i in range(5):
    print(i)

# ================== while loops ===============

# while <contions>:
#       <loop body>
# else:
#     <codes>
# 一定要注意循环条件有更新，存在推出条件；否则陷入死循环

print("===============")
i = 0
while i <= 5:
    print(i)
    i += 1
else:
    print("loop down")

### break  跳出整个循环，程序终止
### continue 跳过本次循环，进入下一次循环

print("===============")
for i in range(1, 10):
    if i == 5:
        break
    print(i)

print("===============")
for i in range(1, 10):
    if i == 5:
        continue
    print(i)

# 计算列表元素的总和

print("===============")
nums = [1, 2, 3, 4, 5]
sums = 0
for i in nums:
    sums += i
print(sums)

print("===============")
# 查找最大值
nums = [3, 2, 9, 4, 5]
max_num = nums[0]
for i in nums:
    if i > max_num:
        max_num = i
print("MAX:", max_num)
